<!DOCTYPE html>
<html>
<head lang="zh">
    <meta charset="UTF-8">
    <title>日志列表</title>
<#include "admin/common.ftl"/>
<#include "admin/permission.ftl"/>
</head>
<body>
<#--工具栏-->
<div id="tb">
    <table cellpadding="0" cellspacing="0">
        <tr>
            <td><div style="margin-top:4px;float:left;">耗时小于: </div><input class="easyui-textbox" id="takingTime" data-options="validType:{min:0,integer:true},onChange:list"></td>
        <#if hasRefresh == "true">
            <td><a href="#" class="easyui-linkbutton" iconCls="icon-search" data-options="plain:true" onclick="list()">搜索</a></td>
        </#if>
        </tr>
    </table>
</div>

<div class="easyui-datagrid" id="datagrid"></div>

<script type="text/javascript" src="${base}/static/levi-js/lib/DateQuery.min.js"></script>
<script type="text/javascript">
    var datagrid = $("#datagrid");
    $(function () {
        list();
    });

    // 加载数据
    function list() {
        datagrid.datagrid({
            url: "${base}/admin/logs/list",
            idField: "id",
            toolbar: "#tb",
            remoteSort: false,
            multiSort: false,
            rownumbers: true,
            singleSelect: false,
            ctrlSelect:true,
            animate: true,
            fit: true,
            border:false,
            pagination:true,
            pageSize: 20,
            pageList: [20,40,60],
            queryParams: {takingTime: $("#takingTime").val()},
            columns: [[
                {field: "id", title: "Id", hidden: true},
                {field: "accountName", title: "操作账号", width: 90},
                {field: "method", title: "方法名", width: 220, formatter: formatMethod},
                {field: "returnVal", title: "返回值", width: 400, formatter: formatReturnVal},
                {field: "startTime", title: "方法执行开始时间", width: 200, formatter: formatDate},
                {field: "endTime", title: "方法执行结束时间", width: 200, formatter: formatDate},
                {field: "takingTime", title: "用时(毫秒)", width: 66, formatter: formatTakingTime},
                {field: "type", title: "类型", width: 86, formatter: formatType}
            ]]
        });
    }

    // 格式化方法
    function formatMethod(val) {
        return "<div title='" + val + "'>" + val + "</div>";
    }

    // 格式化返回值
    function formatReturnVal(val) {
        return "<div title='" + val + "'>" + val + "</div>";
    }

    // 格式化日期
    function formatDate(val, row) {
        return lv.date(val).get("Y-m-d H:i:s ms");
    }

    // 格式化耗时
    function formatTakingTime(val) {
        if (val > 10) return "<div style='color:red;font-weight:bold;'>" + val + "</div>";
        else return "<div style='color:green;font-weight:bold;'>" + val + "</div>";;
    }

    // 格式化类型
    function formatType(val) {
        if (val == "EXCEPTION") return "<div style='color:red;font-weight:bold;'>" + val + "</div>";
        else if (val == "SUCCESS") return "<div style='color:green;font-weight:bold;'>" + val + "</div>";
        else return "<div style='color:grey;font-weight:bold;'>" + val + "</div>";;
    }
</script>
</body>
</html>